package com.cs.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.cs.entity.Result;
import com.cs.pojo.Course;
import com.cs.service.CSService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cs")
public class CsController {

    @Reference
    private CSService csService;

    /***
     * @description 根据学生id查询所有选课
     *
     * @param uid  学生id

     * @date 2019/6/20 22:14
     * @return java.util.List<com.cs.pojo.Cs>
     */
    @RequestMapping("/getCSs.do")
    public List<Course> getCSs(Integer uid) {
        List<Course> courses = null;
        try {
            courses = csService.getCSs(uid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return courses;
    }

    /***
     * @description 根据学生id查询所有未选的课
     *
     * @param uid
     * @date 2019/6/21 20:33
     * @return java.util.List<com.cs.pojo.Course>
     */
    @RequestMapping("/getNoCss.do")
    public List<Course> getNoCss(Integer uid) {
        List<Course> courses = null;
        try {
            courses = csService.getNoCss(uid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return courses;
    }

    /***u
     * @description 选课
     *
     * @param uid  用户id
     * @param cid 课程id
     * @date 2019/6/20 22:10
     */
    @RequestMapping("/addCSs.do")
    public Result addCSs(Integer cid, Integer uid) {
        Result result = null;
        try {
            csService.addCSs(cid, uid);
            result = new Result(true, "选课成功");
        } catch (Exception e) {
            result = new Result(false, e.getMessage());
        }
        return result;
    }

    /***
     * @description 退课
     *
     * @param cid 课程id
     * @param uid 用户id
     * @date 2019/6/20 22:23
     */
    @RequestMapping("/quitCSs.do")
    public Result quitCSs(Integer cid, Integer uid) {
        Result result = null;
        try {
            csService.quitCSs(cid, uid);
            result = new Result(true, "退课成功");
        } catch (Exception e) {
            result = new Result(false, e.getMessage());
        }
        return result;
    }
}
